function Res  = adjFFUsing6Loops(Im)

imageSize=size(Im);
% validity test of the input
if (length(imageSize)~=2) %not a 2D image
   error('Input must be a 2D image');
end

if (imageSize(1)~=imageSize(2))
   error('Input image must be square');
end

if (mod(imageSize(1),2)~=0)
   error('Input image must have even side');
end

% initialize constants and data structures
n=imageSize(1);

m=2*n+1;
Res=zeros(n);
for u=-n/2:n/2-1
    for v=-n/2:n/2-1
        for s=-n/2:n/2-1
            for t=-n/2:n/2-1
                tmp=0;
                for k=-n:n
                    for l=-n/2:n/2        
                            tmp=tmp+exp(2*pi*1i*k*((u-s)-2*l*(v-t)/n)/m)+...
                                exp(2*pi*1i*k*((v-t)-2*l*(u-s)/n)/m);
                    end
                end
                Res(u+n/2+1,v+n/2+1)=Res(u+n/2+1,v+n/2+1)+...
                    Im(s+n/2+1,t+n/2+1)*tmp;
            end
        end
    end
end
   